from typing import List


class Solution:
    def isSelfCrossing(self, distance: List[int]) -> bool:
        # 添加2次距离为0的移动
        distance = [0] * 2 + distance

        for i in range(5, len(distance)):
            # 第1类路径交叉的情况
            if (distance[i] >= distance[i - 2]
                    and distance[i - 1] <= distance[i - 3]):
                return True

            # 第3类路径交叉的情况
            if (distance[i - 3] - distance[i - 5] <= distance[i - 1] <= distance[i - 3]
                    and distance[i] >= distance[i - 2] - distance[i - 4]
                    and distance[i - 2] > distance[i - 4]):
                return True
        return False


if __name__ == "__main__":
    print(Solution().isSelfCrossing(distance=[2, 1, 1, 2]))  # True
    print(Solution().isSelfCrossing(distance=[1, 2, 3, 4]))  # False
    print(Solution().isSelfCrossing(distance=[1, 1, 1, 1]))  # True
